#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python常用模块库 
@File ：异常处理.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2025/2/20 上午1:14 
"""

from shared_memory import SharedMemory, SharedMemoryError

memory_name = "/shm_test_error"
memory_size = 10  # 10 字节

try:
	with SharedMemory(memory_name, memory_size, create=True) as shm:
		large_data = "This is a very long string that exceeds the memory size"
		shm.write(large_data)  # 将触发异常
except SharedMemoryError as e:
	print(f"Caught error: {e}")

# 清理
shm = SharedMemory(memory_name, memory_size, create=False)
shm.unlink()
